<?php
include_once 'lib/config.php';
include_once 'lib/db.php';
include_once 'lib/utils/date.php';
include_once 'model/perbuatan.php';

function inject_head(){?>
    <link rel="stylesheet" type="text/css" href="css/datepicker_vista.css" /> 
    <script type="text/javascript" src="jscript/datepicker.js"></script> 
    <script>
		var orderby_old = null;
		var orderby_type = ['ASC', 'DESC'];
		var orderby_count = 0;
		function updateList(orderby){
			if (orderby==orderby_old) orderby_count++;	
			else orderby_count=0;
			if ($chk(orderby)){
				orderby_str = orderby+" "+orderby_type[orderby_count%2];
				orderby_old = orderby;
			}
			else{
				orderby_str = "";
				orderby_old = "";
			}
			
			key = $('periodeKey').value;
			key2 = $('periodeKey2').value;
			doRequest(APP.action, 'post', 'proc=rank-table&startPeriode='+key+'&endPeriode='+key2+'&orderby='+orderby_str, 
				function (res){ 
					$('rank-table').innerHTML = res;
			});	
		}
	
		var APP = { 
			action: 'proc/admin/ranking.php',
			periode1: null,
			periode2: null
		};
		window.addEvent('domready', function() {
        	APP.periode1 = dtpicker_attach0($('periodeKey'), {timePicker:false, format: 'F-Y', 
				maxDate: { date: <?php echo time()?>, format: 'U' },
				onClose: function(){ 
					APP.periode2.options.minDate = {date:APP.periode1.attachTo.value, format:'U'};
					APP.periode2.formatMinMaxDates();
					updateList(); 
				}
			});
			APP.periode2 = dtpicker_attach0($('periodeKey2'), {timePicker:false, format: 'F - Y', allowEmpty:false, 
				maxDate:{ date: <?php echo time()?>, format: 'U' },
				onClose: function(){ 
					updateList(); 
				}
			});
			updateList();
		});
    </script>
<?php }

include 'view/header.php';
include 'view/admin/ranking/rank.php';
include 'view/footer.php';